package cn.tedu.tmall.front.mall.dao.persist.repository.impl;

import cn.tedu.tmall.front.mall.dao.persist.cache.IDistrictCacheRepository;
import cn.tedu.tmall.front.mall.dao.persist.mapper.ReceiverAddressMapper;
import cn.tedu.tmall.front.mall.dao.persist.repository.IReceiverAddressRepository;
import cn.tedu.tmall.front.mall.pojo.entity.ReceiverAddress;
import cn.tedu.tmall.front.mall.pojo.param.ReceiverAddressUpdateParam;
import cn.tedu.tmall.front.mall.pojo.vo.ReceiverAddressListItemVO;
import cn.tedu.tmall.front.mall.pojo.vo.ReceiverAddressStandardVO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ReceiverAddressRepositoryImpl implements IReceiverAddressRepository {
    @Autowired
    private ReceiverAddressMapper mapper;
    @Autowired
    private IDistrictCacheRepository cacheRepository;
    @Override
    public int insert(ReceiverAddress receiverAddress) {
        return mapper.insert(receiverAddress);
    }

    @Override
    public int deleteById(Long id) {
        return mapper.deleteById(id);
    }


    @Override
    public int updateNonDefaultByUserId(Long userId) {
        ReceiverAddress receiverAddress = new ReceiverAddress();
        receiverAddress.setIsDefault(0);
        QueryWrapper qw = new QueryWrapper();
        qw.eq("user_id",userId);
        return mapper.update(receiverAddress,qw);
    }

    @Override
    public int updateById(ReceiverAddress receiverAddress) {
        return mapper.updateById(receiverAddress);
    }


    @Override
    public ReceiverAddressStandardVO selectById(Long id) {
        ReceiverAddressStandardVO addressStandardVO = mapper.selectById(id);
        return addressStandardVO;
    }

    @Override
    public List<ReceiverAddressListItemVO> listByUserId(Long userId) {
        List<ReceiverAddressListItemVO> addressListItemVOS = mapper.listByUserId(userId);
        return addressListItemVOS;
    }
}
